package com.mes.handler;

import org.codehaus.jettison.json.JSONObject;
import org.openbravo.client.kernel.BaseActionHandler;
import org.openbravo.dal.core.OBContext;
import org.openbravo.dal.service.OBDal;
import org.openbravo.model.common.plm.Product;
import java.util.Map;

/**
 * 计划工单生成备料清单
 */
public class GetMaterialInFoHandler extends BaseActionHandler {
	@Override
	protected JSONObject execute(Map<String, Object> parameters, String data) {

		JSONObject jsonRep = new JSONObject();
		try {
			OBContext.setAdminMode();
			JSONObject reqData = new JSONObject(data);
			String id = reqData.getString("productId");
			// 获取生产数据
			Product em = OBDal.getInstance().get(Product.class, id);
			// 物料名称
			jsonRep.put("Name", em.getName());
			jsonRep.put("Category", em.getProductCategory().getSearchKey());
			jsonRep.put("Uom", em.getUOM().getName());
			if(em.getName2() == null){
				jsonRep.put("Name2", "无");
			}else{
				jsonRep.put("Name2", em.getName2());	
			}
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			OBContext.restorePreviousMode();
		}
		return jsonRep;
	}
}
